<template>
  <div>
    <h1>我是Vue3写的效果</h1>
    <h1 v-show="person.name">姓名:{{ person.name }}</h1>
    <h1>年龄:{{ person.age }}</h1>
    <h1 v-show="person.sex">性别:{{ person.sex }}</h1>
    <h1>工作种类:{{ person.job.type }}</h1>
    <h1>工作薪水:{{ person.job.salary }}</h1>
    <h1>爱好:{{ person.hobby }}</h1>
    <h1>测试的数据c:{{ person.job.a.b.c }}</h1>
    <button @click="changeInfo">修改人的信息</button>
    <button @click="addSex">添加一个sex属性</button>
    <button @click="deleteName">删除name属性</button>
  </div>
</template>

<script>
import {reactive} from "vue";

export default {
  name: 'App',
  setup() {
    let person = reactive({
      name: '张三',
      age: 18,
      job: {
        type: '前端工程师',
        salary: '30K',
        a: {
          b: {
            c: 666
          }
        }
      },
      hobby: ['抽烟', '喝酒', '烫头']
    })


    function changeInfo() {
      person.name = '李四'
      person.age = 48
      person.job.type = 'UI设计师'
      person.job.salary = '60K'
      person.job.a.b.c = 999
      person.hobby[0] = '唱'
      person.hobby[1] = '跳'
      person.hobby[2] = 'rap'
    }


    function addSex() {
      person.sex = '男'
    }

    function deleteName() {
      delete person.name
    }

    return {
      person,
      changeInfo,
      addSex,
      deleteName,
    }
  }
}

</script>

